package com.newer.his.common.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.newer.his.common.entity.Patient;

/**
 * 患者建档表
 * 
 *
 */
@Mapper
public interface PatientMapper {
	
	@Options(useGeneratedKeys = true,keyColumn = "patient_id",keyProperty = "id")
	@Insert("insert into `patient` (`name`,`sex`,`age`,`tel`) values(#{name},#{sex}，#{age},#{tel})") 
	Patient save(Patient patient);
	
	@Select("select patient_id,`name`,sex,age,tel from patient; ")
	List<Patient> findAll();
	
	// 通过名字找患者对象
//	private int id;
//	private String name;
//	private String sex; 
//	private int age;
//	private String tel;
	@Select("select patient_id,`name`,sex,age,tel from patient where patient_id=#{id};") 
	@Results(
			id="", 
			value= {
					@Result(column = "patient_id",property = "id"),
					@Result(column = "name",property = "name"),
					@Result(column = "sex",property = "sex"),
					@Result(column = "age",property = "age"),
					@Result(column = "tel",property = "tel")
				}
			)
	Patient findByid(int id);
	
}
